package com.useeinfo.framework.sugar.tools;

import java.text.DecimalFormat;

/**
 * @Auther: xudong.sun
 * @Date: 2019/2/19 15:02
 * @Description:
 */
public class DataHandleUtil {

    public static String  division(int num1,int num2){
        String rate="0.0%";
        //定义格式化起始位数
        String format="0.0";
        if(num2 != 0 && num1 != 0){
            DecimalFormat dec = new DecimalFormat(format);
            rate =  dec.format((double) num1 / num2*100)+"%";
            while(true){
                if(rate.equals(format+"%")){
                    format=format+"0";
                    DecimalFormat dec1 = new DecimalFormat(format);
                    rate =  dec1.format((double) num1 / num2*100)+"%";
                }else {
                    break;
                }
            }
        }else if(num1 != 0 && num2 == 0){
            rate = "100%";
        }
        return rate;
    }

}
